package com.zhanghe.study.springcloudalibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zh
 * @date 2021/9/13 10:53
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @RequestMapping("/testA")
    public String testA(){
        return "testA";
    }

    @RequestMapping("/testB")
    public String testB(){
        return "testB";
    }

    /**
     * 热点规则
     * @param did
     * @param ip
     * @return
     */
    @RequestMapping("/testC")
    @SentinelResource(value = "/test/testC",blockHandler = "blockHandler")
    public String testC(@RequestParam("did") String did,
                        @RequestParam("ip") String ip){
        return "testC";
    }


    public String blockHandler(String did, String ip, BlockException e){
        return "blockHandler";
    }

    @RequestMapping("/testPersistence")
    public String testPersistence(){
        return "testPersistence";
    }
}
